﻿using lso_2u_Web应用开发.App_Code.Service;
using lso_2u_Web应用开发.Models;
using lso_2u_Web应用开发.Models.Database;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System.Linq;

namespace lso_2u_Web应用开发.ViewComponents
{
    public class UserAvatarInfoViewComponent : ViewComponent
    {
        private readonly DressWorkSystemContext _db;
        private readonly SessionHelper sessionHelper;
        private readonly ServiceClient serviceClient;

        public UserAvatarInfoViewComponent(DressWorkSystemContext db, IHttpContextAccessor httpContextAccessor)
        {
            _db = db;
            sessionHelper = new SessionHelper(httpContextAccessor.HttpContext.Session);
            serviceClient = new ServiceClient(_db);
        }

        public IViewComponentResult Invoke()
        {
            var user = _db.Users.FirstOrDefault(x => x.Id == sessionHelper.UserId);
            return View(user);
        }
    }

}
